package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysBillingMonth;
import com.ruoyi.system.service.ISysBillingMonthService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 月账单Controller
 * 
 * @author ruoyi
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/system/month")
public class SysBillingMonthController extends BaseController
{
    @Autowired
    private ISysBillingMonthService sysBillingMonthService;

    /**
     * 查询月账单列表
     */
    @PreAuthorize("@ss.hasPermi('system:month:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBillingMonth sysBillingMonth)
    {
        startPage();
        List<SysBillingMonth> list = sysBillingMonthService.selectSysBillingMonthList(sysBillingMonth);
        return getDataTable(list);
    }

    /**
     * 导出月账单列表
     */
    @PreAuthorize("@ss.hasPermi('system:month:export')")
    @Log(title = "月账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBillingMonth sysBillingMonth)
    {
        List<SysBillingMonth> list = sysBillingMonthService.selectSysBillingMonthList(sysBillingMonth);
        ExcelUtil<SysBillingMonth> util = new ExcelUtil<SysBillingMonth>(SysBillingMonth.class);
        util.exportExcel(response, list, "月账单数据");
    }

    /**
     * 获取月账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:month:query')")
    @GetMapping(value = "/{billingId}")
    public AjaxResult getInfo(@PathVariable("billingId") Long billingId)
    {
        return success(sysBillingMonthService.selectSysBillingMonthByBillingId(billingId));
    }

    /**
     * 新增月账单
     */
    @PreAuthorize("@ss.hasPermi('system:month:add')")
    @Log(title = "月账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBillingMonth sysBillingMonth)
    {
        return toAjax(sysBillingMonthService.insertSysBillingMonth(sysBillingMonth));
    }

    /**
     * 修改月账单
     */
    @PreAuthorize("@ss.hasPermi('system:month:edit')")
    @Log(title = "月账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBillingMonth sysBillingMonth)
    {
        return toAjax(sysBillingMonthService.updateSysBillingMonth(sysBillingMonth));
    }

    /**
     * 删除月账单
     */
    @PreAuthorize("@ss.hasPermi('system:month:remove')")
    @Log(title = "月账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{billingIds}")
    public AjaxResult remove(@PathVariable Long[] billingIds)
    {
        return toAjax(sysBillingMonthService.deleteSysBillingMonthByBillingIds(billingIds));
    }
}
